<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
      <h1 id="time"></h1>
    <script>
//获取时间
function getTime() {
    let date = new Date();
    let h = date.getHours();
    let m = date.getMinutes();
    let s = date.getSeconds();
    let y = date.getFullYear();
    let M = date.getMonth() + 1;
    let d = date.getDate();
    let m1
    if (m < 10) {
        m1 = 0 + "" + m
    } else {
        m1 = m
    }
    let s1
    if (s < 10) {
        s1 = 0 + "" + s
    } else {
        s1 = s
    }
    let sj = y + "-" + M + "-" + d + "  " + h + ":" + m1 + ":" + s1;
    document.getElementById("time").innerText = sj
}

setTimeout(function () {
    alert("欢迎登陆")
}, 1000)

//设置点击暂停时间和开始
let time = document.getElementById("time")
let index = null
function start() {
    if (index == null) {
        index = setInterval('getTime()', 1000)
        time.setAttribute("title", "时间运行")
    }
}
function stop() {
    clearInterval(index)
    index = null
    time.setAttribute("title", "时间停止")
}
start()
let j = 1
time.onclick = function () {
    if (j % 2 == 1) {
        stop()
    } else {
        start()
    }
    j++
}
    </script>
  </body>
</html>
